generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(62) Show air quality alerts and 3-day forecast for selected zone #29
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edavey
force-pushed
the
62-show-air-quality-alerts
branch
2 times, most recently
from
October 3, 2024 09:17
7ead96f
to
0a06f37
Compare
patrickjfl
force-pushed
the
62-show-air-quality-alerts
branch
2 times, most recently
from
October 4, 2024 11:01
4098430
to
e466283
Compare
These are the forecast zones supported by the CERC API, which we will offer to the user on the forecast page.
We will use this library to make calls to the CERC API in our client.
To facilitate this, I have moved the sample forecast into the test fixtures, and added two new environment variables, CERC_API_HOST_URL and CERC_API_KEY.
We have agree that this method is rendering a single, three day forecast at a time, therefore it should be a show rather than an index method, and forecast should be singular in the path.
Users can now select a zone and fetch live data for that zone from the CERC API
This is so we can load styles more easily when debugging a Capybara integration test which is saved to a local file e.g. with `#save_and_open_page`.
This [mocking library][] will allow us to stub the HTTP response from CERC which our `CercApiClient` receives. We'll use it to set up scenarios for our integration tests. [mocking library]: https://github.com/bblimke/webmock
We have two scenarios: 1. "View air quality alerts": we see an alert with a different warning status for each of the 3 days included in the forecast 2. "See confirmation that there are current no air quality alert": We see that there are no alerts We introduce three test helper modules: 1. a `Fixtures` module to build Forecasts for our tests 2. a `HttpStub` module to set WebMock stubs on HTTP traffic 3. an `AirQualitySteps` module to manage the implementation details for each "step" in the test. In our `view_air_quality_alerts_spec.rb` feature spec we ["include"][] this module in order to have access to its methods. This leaves the acceptance test clean and focused on describing the expected behaviour. ["include"]: https://ruby-doc.org/docs/ruby-doc-bundle/ProgrammingRuby/book/classes.html#UC
Thanks to Prettier linter
One of our 2 acceptance tests now passes (albeit with a naive implementation in the controller!) ``` scenario "See confirmation that there are current no air quality alert" given_an_air_pollution_prediction_for_today_w_low_status and_an_air_pollution_prediction_for_tomorrow_w_low_warning_status and_an_air_pollution_prediction_for_day_after_tomorrow_w_low_warning_status and_the_response_from_cercs_api_is_stubbed_accordingly when_i_look_at_the_forecasts then_i_see_that_there_are_no_current_air_quality_alerts ```
- stub environment variables - use an inline JSON fixture for clarity
We implement a `ForecastSteps` module for our helper methods.
Each row in the table now has a class describing the information it carries: - `air-pollution` - `uv` - `pollen` - `temperature` Each of the "value cells" now has a [`data-*` attribute][] of `data-date` to identify which day's value it contains. This will allow our integration tests to be clear and maintainable. [`data-*` attribute]: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
I couldn't for now figure out how to resolve these warnings. I tried updating all gems to their latest versions. There isn't a more recent Ruby version to try. Come back to this later, maybe. ``` air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/date_time_parser.rb:837: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/date_time_parser.rb:691: warning: assigned but unused variable - testEof air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32457: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32618: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32654: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32743: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32759: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32825: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32866: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:32891: warning: statement not reached air-text/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/parsers/address_lists_parser.rb:31987: warning: assigned but unused variable - testEof air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/functions.rb:7: warning: method redefined; discarding old asset_data_url air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_processor.rb:274: warning: previous definition of asset_data_url was here air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:7: warning: method redefined; discarding old initialize air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_compressor.rb:39: warning: previous definition of initialize was here air-text/vendor/bundle/ruby/3.3.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:17: warning: method redefined; discarding old call air-text/vendor/bundle/ruby/3.3.0/gems/sprockets-4.2.1/lib/sprockets/sass_compressor.rb:49: warning: previous definition of call was here air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge/log_subscribers/base.rb:44: warning: method redefined; discarding old extract_status air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge/log_subscribers/base.rb:41: warning: previous definition of extract_status was here air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:82: warning: method redefined; discarding old ignore_tests air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:28: warning: previous definition of ignore_tests was here air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:82: warning: method redefined; discarding old ignore_tests air-text/vendor/bundle/ruby/3.3.0/gems/lograge-0.14.0/lib/lograge.rb:28: warning: previous definition of ignore_tests was here ```
We take a representation of a Forecast from CERC's API and build a list of our own Forecast entities. For now our ForecastBuilder only uses the first zone returned (i.e. only handles the scenario where we've asked CERC's API for information on a particular zone). We will likely develop this to handle all zones: that's what's returned if we don't request a specific zone e.g. ``` curl "https://cerc.example.com/getforecast/all?numdays=3 ``` For now we also leave out the rain and wind information as we aren't sure how/if/where this is needed.
`Forecast#inspect` will return a string representation like: ``` "#<Forecast @obtained_at=2024-10-02 15:38:00 +0100 @forecast_for=2024-10-02 @zone=#<ForecastZone @id=29 @name=Southwark @type=1> @air_pollution=#<AirPollutionPrediction @forecasted_at=2024-10-02 15:50:00 +0100 @nitrogen_dioxide=1> @particulate_matter_10=1 @particulate_matter_2_5=1 @ozone=2 @overall_score=2 @overall_label=LOW> @UV=2 @pollen=-999 @temperature=#<TemperaturePrediction @min=10.0 @max=16.6>> ```
We are going to build test fixtures for our own `Forecast` entities as distinct from the JSON representations which we receive from CERC's `/getforecast/all?` endpoint.
We will implement these alerts properly in coming commits.
We need a way to build our `Forecast` domain entities (and their `AirPollutionPrediction`, `TemperaturePrediction`, `ForecastZone` component entities). We use [FactoryBot][] to help. [FactoryBot]: https://github.com/thoughtbot/factory_bot
The DAQI scale is from 1 to 10: 1-3 = Low 4-6 = Moderate 7-9 = High 10 = Very high
edavey
force-pushed
the
62-show-air-quality-alerts
branch
from
October 7, 2024 10:36
fe168d0
to
dcc4815
Compare
edavey
changed the title
WIP (62) show air quality alerts
(62) Show air quality alerts and 3-day forecast for selected zone
Oct 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR we implement two stories which rely on data from CERC's "London-airTEXT" API
We've included guidance in the UV row, and will add guidance to the other rows as appropriate in future PRs.
3 day forecasts with guidance for UV
No air quality alerts to display
Air quality alerts for each of the 3 days forecast (guidance unexpanded)
Air quality alerts for each of the 3 days forecast (guidance expanded)